vim.keymap.set("n", "ct", "<cmd>GitConflictChooseTheirs<cr>")
vim.keymap.set("n", "co", "<cmd>GitConflictChooseOurs<cr>")
vim.keymap.set('n', '<leader>gg', function()
  local Terminal = require("toggleterm.terminal").Terminal
  local lazygit = Terminal:new {
    cmd = "lazygit",
    hidden = true,
    direction = "float",
    float_opts = {
      border = "none",
      width = 100000,
      height = 100000,
      zindex = 200,
    },
    on_open = function(_)
      vim.cmd "startinsert!"
    end,
    on_close = function(_) end,
    count = 99,
  }
  lazygit:toggle()
end, { desc = 'lazygit' })
return {
  {
    "lewis6991/gitsigns.nvim",
    dependencies = {
      "nvim-telescope/telescope.nvim",
    },
    opts = {
      signs = {
        add = { text = "│" },
        change = { text = "│" },
        delete = { text = "󰍵" },
        topdelete = { text = "‾" },
        changedelete = { text = "~" },
        untracked = { text = "│" },
      },

      on_attach = function(bufnr)
        local gs = package.loaded.gitsigns

        local function map(mode, l, r, opts)
          opts = opts or {}
          opts.buffer = bufnr
          vim.keymap.set(mode, l, r, opts)
        end

        -- Navigation
        map("n", "]c", function()
          if vim.wo.diff then
            return "]c"
          end
          vim.schedule(function()
            gs.next_hunk()
          end)
          return "<Ignore>"
        end, { expr = true, desc = 'go to next git change' })

        map("n", "[c", function()
          if vim.wo.diff then
            return "[c"
          end
          vim.schedule(function()
            gs.prev_hunk()
          end)
          return "<Ignore>"
        end, { expr = true, desc = 'go to previous git change' })

        -- Actions
        map("n", "<leader>ga", gs.stage_buffer, { desc = "git add current buffer" })
        map("n", "<leader>gr", gs.reset_buffer, { desc = "git reset HEAD for current buffer" })
        map("n", "<leader>gb", function()
          gs.blame_line { full = true }
        end, { desc = "git blame" })
        map("n", "<leader>gd", function()
          gs.diffthis "HEAD"
        end, { desc = "git diff this with HEAD" })
        map("n", "<leader>gt", gs.toggle_deleted, { desc = "git toggle diff in current buffer" })

        -- Text object
        map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
      end,
    },
  },
  {
    "akinsho/git-conflict.nvim",
    config = function()
      require("git-conflict").setup {
        default_mappings = true,    -- disable buffer local mapping created by this plugin
        disable_diagnostics = true, -- This will disable the diagnostics in a buffer whilst it is conflicted
        highlights = {
          incoming = "DiffText",
          current = "DiffAdd",
        },
      }
    end,
  },
}
